﻿using System;

namespace OCXS.OCXSAdministration {

    /// <summary>
    /// Represents a variable.
    /// </summary>
    [Serializable]
    public class VariableRepresentation {

        /// <summary>
        /// Name of the variable.
        /// </summary>
        protected string variableName;

        /// <summary>
        /// Type of the variable.
        /// </summary>
        protected string variableType;

        /// <summary>
        /// Description for the variable
        /// </summary>
        protected string variableDescription;

        /// <summary>
        /// Latest values.
        /// </summary>
        protected float[] variableValues;

        /// <summary>
        /// Gets or sets the name of the variable.
        /// </summary>
        public string VariableName {
            get { return this.variableName; }
            set { this.variableName = value; }
        }

        /// <summary>
        /// Gets or sets the type of the variable
        /// </summary>
        public string VariableType {
            get { return this.variableType; }
            set { this.variableType = value; }
        }

        /// <summary>
        /// Gets or sets the description of the variable.
        /// </summary>
        public string VariableDescription {
            get { return this.variableDescription; }
            set { this.variableDescription = value; }
        }
        
        /// <summary>
        /// Gets or sets the values of the variable.
        /// </summary>
        public float[] VariableValues {
            get { return this.variableValues; }
            set { this.variableValues = value; }
        }

        protected VariableRepresentation() {
        }

        /// <summary>
        /// Constructs a representation using a name, a type and description.
        /// </summary>
        /// <param name="name">Name of the variable.</param>
        /// <param name="type">Type of the variable.</param>
        /// <param name="description">Description of the variable.</param>
        public VariableRepresentation(string name, string type, string description, int size = 10) {
            this.variableName = name;
            this.variableType = type;
            this.variableDescription = description;
            this.variableValues = new float[size];
            for (int i = 0; i < size; i++)
                this.variableValues[i] = 0.0f;
        }

        /// <summary>
        /// COnstructs a representation providing values too.
        /// </summary>
        /// <param name="name">Name of the variable.</param>
        /// <param name="type">Type of the variable.</param>
        /// <param name="description">Description of the variable.</param>
        /// <param name="initialValues">Initial values as an array.</param>
        public VariableRepresentation(string name, string type, string description, float[] initialValues, int size = 10)
                : this(name, type, description, size) {
            this.variableValues = initialValues;
        }

        /// <summary>
        /// Adds by shift the new value removing the most aged one.
        /// </summary>
        /// <param name="val">Value to add by shift</param>
        public void AddValue(float val) {
            for (int i = 0; i < this.variableValues.Length - 1; i++) {
                this.variableValues[i] = this.variableValues[i + 1];
            }
            this.variableValues[this.variableValues.Length - 1] = val;
        }

    }


    [Serializable]
    public class VariableConfigurationRepresentation : VariableRepresentation {
        
        /// <summary>
        /// 
        /// </summary>
        protected string variablePath;
        
        /// <summary>
        /// 
        /// </summary>
        protected string mu;

        /// <summary>
        /// 
        /// </summary>
        protected int periodUpdate;

        /// <summary>
        /// 
        /// </summary>
        protected string generatingFunction;

        /// <summary>
        /// 
        /// </summary>
        protected string staticValues;

        /// <summary>
        /// 
        /// </summary>
        public string VariablePath {
            get { return this.variablePath; }
            set { this.variablePath = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string MU {
            get { return this.mu; }
            set { this.mu = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int PeriodUpdate {
            get { return this.periodUpdate; }
            set { this.periodUpdate = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string GeneratingFunction {
            get { return this.generatingFunction; }
            set { this.generatingFunction = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string StaticValues {
            get { return this.staticValues; }
            set { this.staticValues = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public VariableConfigurationRepresentation() : base() {
        }

        public VariableConfigurationRepresentation(
                    string path,
                    string name,
                    string type, 
                    string description,
                    string mu,
                    int periodUpdate,
                    string generatingFunction,
                    string staticValues) 
                : base(name, type, description) {
            
            this.variablePath = path;
            this.mu = mu;
            this.periodUpdate = periodUpdate;
            this.generatingFunction = generatingFunction;
            this.staticValues = staticValues;

        }

    }

    [Serializable]
    public class SubscriptionRepresentation
    {

        /// <summary>
        /// 
        /// </summary>
        private string sid;

        /// <summary>
        /// 
        /// </summary>
        private bool disposed;

        /// <summary>
        /// 
        /// </summary>
        private string[] variableIds;

        /// <summary>
        /// 
        /// </summary>
        public string SID {
            get { return this.sid; }
            set { this.sid = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool Disposed {
            get { return this.disposed; }
            set { this.disposed = value; }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public string[] VariableIds {
            get { return this.variableIds; }
            set { this.variableIds = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private SubscriptionRepresentation() {
            this.sid = "";
            this.disposed = false;
            this.variableIds = null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="ids"></param>
        public SubscriptionRepresentation(string sid, bool disposed, string[] ids) {
            this.sid = sid;
            this.disposed = disposed;
            this.variableIds = ids;
        }

    }

}